package com.example.demo.crawler;

import com.example.demo.processor.ContentProcessor;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class DeafaultCrawlerImpl implements Crawler {

    public static void main(String[] args)
    {
        DeafaultCrawlerImpl crawler=new DeafaultCrawlerImpl();
        String extract = crawler.extract("https://www.dingdiann.com/ddk74633/4684466.html");
        ContentProcessor contentProcessor =new ContentProcessor();
//        String process = contentProcessor.process(extract);
//        System.out.println(process);

    }

    @Override
    public String extract(String url) {
        RestTemplate restTemplate=new RestTemplate();
//        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
//        requestFactory.setReadTimeout(10000);
//        requestFactory.setConnectTimeout(30000);
//        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("125.121.114.46", 808));
//
//        requestFactory.setProxy(proxy);
//
//        restTemplate.setRequestFactory(requestFactory);

//        String content = restTemplate.getForObject("https://www.dingdiann.com/searchbook.php?keyword=斗破&page=1", String.class);
        String content = restTemplate.getForObject(url, String.class);
//        System.out.println(content);
        return content;
    }
}
